﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Controls_Activity_ActivityChoose : BaseUserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            literalModalPopup.Text = "请选择办公流程";
            InitDate();
        }
    }

    public string Subject
    {
        get
        {
            return ViewState["Subject"].ToString();
        }
    }

    public string CategoryCode
    {
        get
        {
            return ViewState["CategoryCode"].ToString();
        }
    }

    public string GroupCode
    {
        get
        {
            return ViewState["GroupCode"].ToString();
        }
    }

    public string ActivityControl
    {
        get
        {
            return ViewState["ActivityControl"].ToString();
        }
    }

    public void Show()
    {
        InitDate();
        modalPopup.Show();
    }

    public void InitDate()
    {
        string cmdText = @"select a.*,b.CodeName GroupCodeName from T_WorkflowCategory a 
                left join T_CodeConfig b on a.GroupCode=b.CodeValue and 
                b.Category='WorkflowGroup' order by OrderIndex";
        DataSet ds = BaseAccess.GetDataSet(base.Connection, cmdText);
        gridView.DataSource = ds.Tables[0];
        gridView.DataBind();
    }

    public EventHandler OnSelect;

    protected void btnModalPopupOK_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(Request["CategoryID"]))
        {
            base.Alert("请选择一条记录");
            InitDate();
            return;
        }
        string cmdText = @"select a.*, b.CodeName GroupCodeName from T_WorkflowCategory a 
                left join T_CodeConfig b on a.GroupCode=b.CodeValue and 
                b.Category='WorkflowGroup' and a.CategoryID='{0}' order by OrderIndex";
        DataSet ds = BaseAccess.GetDataSet(base.Connection, string.Format(cmdText, Request["CategoryID"]));

        ViewState["Subject"] = ds.Tables[0].Rows[0]["GroupCodeName"].ToString() + " - " 
                + ds.Tables[0].Rows[0]["Subject"].ToString();
        ViewState["CategoryCode"]= ds.Tables[0].Rows[0]["CategoryCode"].ToString();
        ViewState["GroupCode"] = ds.Tables[0].Rows[0]["GroupCode"].ToString();
        ViewState["ActivityControl"] = ds.Tables[0].Rows[0]["ActivityControl"].ToString();
        modalPopup.Hide();
        if (OnSelect != null)
        {
            OnSelect(null, null);
        }
    }

    protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //((HyperLink)e.Row.Cells[1].Controls[0]).ToolTip = ((HiddenField)e.Row.Cells[0].Controls[1]).Value;
        }
    }
}
